<?php


namespace Modules\Cms\Http\Controllers\Admin;


use App\Http\Controllers\MyController;
use Illuminate\Http\Request;
use Modules\Cms\Http\Requests\ArticleRequest;
use Modules\Cms\Models\Article;
use App\Models\ArticleHonor;
use App\Models\UserHonor;


class MyHonor extends MyController
{

    public function index(Request $request)
    {
        if ($request->ajax() && $request->wantsJson()) {

            $category = UserHonor::with('user')->orderBy('id', 'desc')
                ->where($this->adminFilter($request->input('filter'), [
                    'user_id' => function ($value) {
                        return ['user_id', '=', $value];
                    }, 'honor.title' => function ($value) {
                        $category = ArticleHonor::where('title', $value)->first();
                        return ['honor_id', '=', $category->id ?? 0];
                    }
                ]))
                ->paginate($this->request('limit', 'intval'))->toArray();

            return $this->jsonSuc($category);
        }
        return $this->view('admin.userhonor.index');
    }
}